#include <stdio.h>

int father[30001], number[30001];

/**************************************
* Funciont Name: find_set
* Params: int x
* Return: int
* Description: 
**************************************/

int find_set (int x)
{

    int a = x, temp;
    /*寻找x所在结合的根节点*/
    while (father[a] != a) {
        a = father[a];
    }
    /*将所有中间节点的父节点标为根节点*/
    while (a != x) {
        temp = father[x];
        father[x] = a;
        x = temp;
    }

    return a;
}

/**************************************
* Funciont Name: union_set
* Params: int a, int b
* Return: void
* Description: 
**************************************/

void union_set (int a, int b)
{

    a = find_set(a);
    b = find_set(b);

    /*a和b已经在同一个集合中，不需要合并*/
    if (a == b) {
        return; 
    }

    /*合并，小集合并入大集合*/
    /*更新集合元素个数*/
    if (number[a] >= number[b]) {
        father[b] = a;
        number[a] += number[b];
    } else {
        father[a] = b;
        number[b] += number[a];
    }

    return;
}

int main (int argc, char const* argv[])
{

    int n, m, i, j;
    while (scanf("%d %d", &n, &m) != EOF && (n || m)) {
        for (i = 0; i < n; i++) {
            father[i] = i;
            number[i] = 1;
        }
        for (i = 0; i < m; i++) {
            int a, k, b;
            scanf("%d %d", &k, &a);
            for (j = 1; j < k; j++) {
                scanf("%d", &b);
                union_set(a, b);
            }
        }

        printf("%d\n", number[find_set(0)]);
    }

    return 0;
}
